# Table 3 Stated Objectives in 13D Filings broken Down by Investor Type 

# topic difference in financial vs nonfinancial types

df_2types = pd.read_csv('data/accno_cik_type_topics.txt', sep='|', names=['accno','cik','type','msv','undervalued','econ_market_industry','capital_structure','dividend','repurchase','restructure','nominate_elect','vacancy','operations'])

df_2types['msv'] = (df_2types['msv']>0).astype(int)
df_2types['undervalued'] = (df_2types['undervalued']>0).astype(int)
df_2types['msv_undervalued'] = ((df_2types['msv'] + df_2types['undervalued'])>0).astype(int)
df_2types['econ_market_industry'] = (df_2types['econ_market_industry']>0).astype(int)
df_2types['capital_structure'] = (df_2types['capital_structure']>0).astype(int)
df_2types['dividend'] = (df_2types['dividend']>0).astype(int)
df_2types['repurchase'] = (df_2types['repurchase']>0).astype(int)
df_2types['restructure'] = (df_2types['restructure']>0).astype(int)
df_2types['nominate_elect'] = (df_2types['nominate_elect']>0).astype(int)
df_2types['vacancy'] = (df_2types['vacancy']>0).astype(int)
df_2types['nominate_elect_vacancy'] = ((df_2types['nominate_elect'] + df_2types['vacancy'])>0).astype(int)
df_2types['operations'] = (df_2types['operations']>0).astype(int)

import statsmodels.formula.api as smf
from statsmodels.iolib.summary2 import summary_col

def tab(words):
    reg1 = smf.ols(formula=f"{words} ~ C(type) ", data=df_2types).fit()
    print(f'{words} | {(reg1.params.iloc[0] + reg1.params.iloc[1]) *100: 0.2f} | {reg1.params.iloc[0]*100: 0.2f} | {reg1.pvalues.iloc[1]*100 :0.3f}')

print('topic | nonfinancial | financial | p-value of diff') 
print('-'*60)
tab('msv')
tab('undervalued')  
tab('msv_undervalued')
tab('econ_market_industry')
tab('capital_structure')
tab('dividend')
tab('repurchase')
tab('restructure')
tab('nominate_elect')
tab('vacancy')
tab('nominate_elect_vacancy')
tab('operations')


# topic differences in 4 investor types


df_4types = pd.read_csv('data/accno_cik_4type_topics.txt', sep='|', names=['accno','cik','type','msv','undervalued','econ_market_industry','capital_structure','dividend','repurchase','restructure','nominate_elect','vacancy','operations'])

df_4types['msv'] = (df_4types['msv']>0).astype(int)
df_4types['undervalued'] = (df_4types['undervalued']>0).astype(int)
df_4types['msv_undervalued'] = ((df_4types['msv'] + df_4types['undervalued'])>0).astype(int)
df_4types['econ_market_industry'] = (df_4types['econ_market_industry']>0).astype(int)
df_4types['capital_structure'] = (df_4types['capital_structure']>0).astype(int)
df_4types['dividend'] = (df_4types['dividend']>0).astype(int)
df_4types['repurchase'] = (df_4types['repurchase']>0).astype(int)
df_4types['restructure'] = (df_4types['restructure']>0).astype(int)
df_4types['nominate_elect'] = (df_4types['nominate_elect']>0).astype(int)
df_4types['vacancy'] = (df_4types['vacancy']>0).astype(int)
df_4types['nominate_elect_vacancy'] = ((df_4types['nominate_elect'] + df_4types['vacancy'])>0).astype(int)
df_4types['operations'] = (df_4types['operations']>0).astype(int)

def tab(words):
    reg1 = smf.ols(formula=f"{words} ~ C(type) ", data=df_4).fit()
    print(f'{words} | {(reg1.params.iloc[0] + reg1.params.iloc[2]) *100: 0.2f} | {(reg1.params.iloc[0] + reg1.params.iloc[1]) *100: 0.2f} | {(reg1.params.iloc[0] + reg1.params.iloc[3]) *100: 0.2f} | {reg1.params.iloc[0]*100: 0.2f} ')

print('topic | individual | hedge funds | other private | institutional') 
print('-'*60)
tab('msv')
tab('undervalued')  
tab('msv_undervalued')
tab('econ_market_industry')
tab('capital_structure')
tab('dividend')
tab('repurchase')
tab('restructure')
tab('nominate_elect')
tab('vacancy')
tab('nominate_elect_vacancy')
tab('operations')


# topic differences in short-term vs long-term investor types



df_stlt = pd.read_csv('data/accno_cik_st_lt_topics.txt', sep='|', names=['accno','cik','type','msv','undervalued','econ_market_industry','capital_structure','dividend','repurchase','restructure','nominate_elect','vacancy','operations'])

df_stlt['msv'] = (df_stlt['msv']>0).astype(int)
df_stlt['undervalued'] = (df_stlt['undervalued']>0).astype(int)
df_stlt['msv_undervalued'] = ((df_stlt['msv'] + df_stlt['undervalued'])>0).astype(int)
df_stlt['econ_market_industry'] = (df_stlt['econ_market_industry']>0).astype(int)
df_stlt['capital_structure'] = (df_stlt['capital_structure']>0).astype(int)
df_stlt['dividend'] = (df_stlt['dividend']>0).astype(int)
df_stlt['repurchase'] = (df_stlt['repurchase']>0).astype(int)
df_stlt['restructure'] = (df_stlt['restructure']>0).astype(int)
df_stlt['nominate_elect'] = (df_stlt['nominate_elect']>0).astype(int)
df_stlt['vacancy'] = (df_stlt['vacancy']>0).astype(int)
df_stlt['nominate_elect_vacancy'] = ((df_stlt['nominate_elect'] + df_stlt['vacancy'])>0).astype(int)
df_stlt['operations'] = (df_stlt['operations']>0).astype(int)

import statsmodels.formula.api as smf
from statsmodels.iolib.summary2 import summary_col

def tab(words):
    reg1 = smf.ols(formula=f"{words} ~ C(type) ", data=df_stlt).fit()
    print(f'{words} | {(reg1.params.iloc[0] + reg1.params.iloc[1]) *100: 0.2f} | {reg1.params.iloc[0]*100: 0.2f} | {reg1.pvalues.iloc[1]*100 :0.3f}')

print('topic | short-term | long-term | p-value of diff') 
print('-'*60)
tab('msv')
tab('undervalued')  
tab('msv_undervalued')
tab('econ_market_industry')
tab('capital_structure')
tab('dividend')
tab('repurchase')
tab('restructure')
tab('nominate_elect_vacancy')
tab('nominate_elect')
tab('vacancy')
tab('operations')
